import { observable, action } from 'mobx';
import { RouteLayout, ListAdvanced } from 'weaver-mobile-page';

export default class CustomerListStore {
  comObj = {};
  params = {};
  @observable listAd = {};
  @observable list = {};
  @observable initResponsed = false;// 是否已经得到初始化数据的响应
  @observable initSuccessed = false;// 初始化数据是否获取成功
  @observable initFailedMsg = "";   // 初始化处理失败的原因
  @observable customerCardLayout = {};

  @action
  doNew = (comObj, params) => {
    this.comObj = comObj;
    this.params = params;
  }

  @action
  doInit = () => {
    this.initResponsed = true;
    this.initSuccessed = true;
    const currentPath = this.comObj.props.location.pathname;
    this.customerCardLayout = new RouteLayout.Store({ route: currentPath, id: 'customerCardLayout' });
    this.listAd = new ListAdvanced.Store({ route: currentPath, id: 'hrmCustomerList' });
    this.doSearch();
  }


  @action
  doSearch = () => {
    const { searchAdvancedStore, listViewStore, searchParams } = this.listAd;
    let params = {};
    // 获取高级搜索参数
    if (searchAdvancedStore) {
      const { formParams } = searchAdvancedStore.form;
      params = { ...this.params, ...formParams, ...searchParams };
    } else {
      params = { ...this.params, ...searchParams };
    }
    // 清除列表数据
    listViewStore.clearData();
    this.listAd.getData({ url: '/api/crm/mobile/getCustomerListResult', params });
  }



  @action
  doClear = () => {
    this.initResponsed = false;
    this.initSuccessed = false;
    this.initFailedMsg = "";
  }

}